package com.qutan.app.core.utils;

import org.springframework.web.bind.ServletRequestUtils;

import javax.servlet.http.HttpServletRequest;


/**
 * Created by oyhk on 14-6-29.
 * <p>
 * 客户端工具类
 */
public class RequestUtils extends ServletRequestUtils {

    public static String getIpAddress(HttpServletRequest request) {
        String ip = request.getHeader("x-forwarded-for");
        if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("Proxy-Client-IP");
        }
        if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("WL-Proxy-Client-IP");
        }
        if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getRemoteAddr();
        }
        return ip;
    }
}
